<template>
  <div class="main">
    <el-row>
      <el-form :inline="true" label-width="80px" labelPosition="left" :model="searchForm">
        <el-col :span="18">
          <el-form-item label="关键字">
            <el-input v-model="searchForm.keyword" placeholder="请输入" style="width:300px"></el-input>
          </el-form-item>
          <el-button type="primary" icon="el-icon-search" @click.native="searchAgent">搜索</el-button>
          <el-button type="primary" icon="el-icon-plus" @click.native="addAdder = true">新建</el-button>
        </el-col>
      </el-form>
    </el-row>
    <el-row>
      <el-table
        :data="addersList"
        :cell-style="$rowstyle"
        :header-cell-style="$headerstyle"
        style="width: 100%"
        max-height="250"
      >
        <el-table-column prop="city" label="城市" align="center"></el-table-column>
        <el-table-column prop="name" label="代理商" align="center"></el-table-column>
        <el-table-column prop="contact" align="center" label="联系人"></el-table-column>
        <el-table-column prop="mobile" align="center" label="电话"></el-table-column>
        <el-table-column prop="created_at" align="center" label="创建日期"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="adderChoose(scope.row)"
              type="text"
              size="small"
              v-if="adder.id != scope.row.id"
            >选择</el-button>
            <el-button
              @click.native.prevent="adderCancelChoose(scope.row)"
              type="text"
              size="small"
              v-else
            >取消选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @current-change="handlePageChange"
        :current-page.sync="currentPage"
        :page-size="4"
        layout="prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-row>
    <!-- <addAdder v-if="addAdder"></addAdder>  -->
    <el-dialog custom-class='noname' :title="null" :show-close='false' append-to-body  :visible.sync="addAdder" center width="900px">
     <addAdderBox @closeAdd='closeAdd'></addAdderBox> 
    </el-dialog>
  </div>
</template>

<script>
import { Choice_advertisers } from "../../../api/Salesman.js";
import addAdderBox from '../../market_manage/components/addAdderBox.vue'
import { SETDATE } from "../../../api/System.js";
export default {
  props: ["adder",'adderId'],
  components:{
      addAdderBox
  },
  data() {
    return {
      searchForm: {
        keyword: ""
      },
      total: 0,
      currentPage: 1,
      addersList: [],
      addAdder:false
    };
  },
  methods: {
    getChoice_advertisers() {
      var data = {
        name: this.searchForm.keyword,
        page: this.currentPage,
        per: 4,
        id: this.adderId
      };
      Choice_advertisers(data).then(res => {
        if (res.code == 200) {
          this.addersList = res.data.data;
          this.currentPage = res.data.current_page;
          this.total = res.data.total;
          this.addersList.forEach(element => {
            element.created_at = SETDATE(element.created_at, true);
          });
        }
      });
    },
    searchAgent(){
        this.getChoice_advertisers()
    },
    closeAdd(){
        this.addAdder = false
        this.getChoice_advertisers()
    },
    handlePageChange() {
      this.getChoice_advertisers();
    },
    adderChoose(data) {
      this.$emit("adderChoose", data);
    },
    adderCancelChoose() {
      this.$emit("adderCancelChoose");
    }
  },
  mounted() {
    this.getChoice_advertisers();
  }
};
</script>

<style scoped>
.main {
  width: 100%;
  height: 100%;
}
.main .noname>.el-dialog__header{
    padding: 0;
}
.main .noname>.el-dialog__body{
    padding: 0;
    width: 1000px;
}
</style>